/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package percussiongenerator.commands;

import java.util.Collection;
import org.jfonia.model.Sequence;
import org.jfonia.model.Staff;

/**
 *
 * @author Jannes Plyson
 */
public class Duplicate implements ICommand{
    private Staff staff;
    int numberOfDuplicates;

    public Duplicate(Staff staff, int numberOfDuplicates){
        this.staff = staff;
        this.numberOfDuplicates = numberOfDuplicates;
    }

    public void execute() {        
        staff.duplicate(numberOfDuplicates);                
    }

    public void undo() {
        Collection<Sequence> sequences = staff.getSequences();
        int length = staff.getLength();
        for(Sequence seq: sequences){
            int newSize = seq.size()/numberOfDuplicates;
            while(seq.size() > newSize){
                seq.remove(0);
            }
        }
    }

}
